import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.util.Observable;
import java.util.Observer;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;


@SuppressWarnings("serial")
public class CellPanel extends JPanel implements Observer {
	
	private JLabel mElevationLabel, mTypeLabel, mDeveloperOwnerLabel;

	@Override
	public void update(Observable o, Object arg) {
		// TODO Auto-generated method stub
		System.out.println("updating");
		
		DisplayableCell cell = (DisplayableCell)o;
		updateDisplay(cell.getElevation(), cell.getType(), cell.getDeveloperOwner());
	}
	
	public CellPanel(){
		super();
		setBackground(Color.RED);
        setBorder(BorderFactory.createLineBorder(new Color(0, 0, 255)));
		initLayout();
	}
	
	private void initLayout() {
		mElevationLabel = new JLabel("");
		mElevationLabel.setFont(new Font("Lucida Grande", 0, 18)); 
		mElevationLabel.setPreferredSize(new Dimension(115, 22));
		mElevationLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
        this.add(mElevationLabel);
        
        mTypeLabel = new JLabel("");
        mTypeLabel.setFont(new Font("Lucida Grande", 0, 10)); 
        mTypeLabel.setHorizontalAlignment(SwingConstants.CENTER);
        mTypeLabel.setPreferredSize(new Dimension(60, 60));
        mTypeLabel.setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0)));
        this.add(mTypeLabel);
        
        mDeveloperOwnerLabel = new JLabel("");
        mDeveloperOwnerLabel.setFont(new Font("Lucida Grande", 1, 36));
        mDeveloperOwnerLabel.setHorizontalAlignment(SwingConstants.LEFT);
        mDeveloperOwnerLabel.setPreferredSize(new Dimension(115, 32));
        mDeveloperOwnerLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
        this.add(mDeveloperOwnerLabel);
	}
	
	private void updateDisplay(int elevation, String type, int developerOwner){
		mElevationLabel.setText("" + elevation);
		mTypeLabel.setText("" + type);
		mDeveloperOwnerLabel.setText("" + developerOwner);
	}
	
}
